General utility functions for the simulations

General utility functions and classes for the simulation

class qmatchatea.utils.utils.QCCheckpoints(PATH='data/checkpoints/', frequency=-1, input_nml='input.nml', restart=None)[source]

Class to handle checkpoint parameters

Parameters

PATH: str, optional

PATH to the checkpoint directory. Default data/checkpoints/.

frequency: float, optional

Decide the frequency, in hours, of the checkpoints. If negative no checkpoints are present. Default to -1.

input_nml: str, optional

Name of the input namelist. Default ‘input.nml’

restart: int, optional

If an int is provided, it is the checkpoint counter from which the user wants to restart. Default to None.

property PATH

PATH property

property frequency

Checkpoint frequency property

classmethod from_json(path)[source]

Initialize the class from a json file

property input_nml

Input namelist property

restart_from_checkpoint(initial_state)[source]

Restart from the checkpoint passed in the initialization.

Parameters

initial_state: str | List[Tensors] | _AbstractTN

The initial state of the simulation. Might be overwritten on exit.

Returns

str | List[Tensors] | _AbstractTN

The new initial state. If self.restart is None, it is the old initial state.

save_checkpoint(operation_idx, emulator)[source]

Save the state for the checkpoint if the operation_idx exceeded the frequency of the checkpoints

Parameters

operation_idxint

Index of the current operation in the quantum circuit

emulator: _AbstractTN

Tensor network class

Returns

None

set_up(input_dict, operators=<qmatchatea.utils.tn_utils.QCOperators object>, observables=<qtealeaves.observables.tnobservables.TNObservables object>, circ='')[source]

Set up the checkpoints directory

Parameters

input_dictdict

Input parameter dictionary

operatorsQCOperators, optional

Tensor operators

obervables:py:class: TNObservables, optional

Tensor observables

circ_str: str or QuantumCircuit

String representing the qiskit quantum circuit

to_dict()[source]

Return the ordered dictionary of the properties of the class.

Returns

dictionary: OrderedDict

Ordered dictionary of the class properties

to_json(path)[source]

Write the class as a json on file

class qmatchatea.utils.utils.QCConvergenceParameters(max_bond_dimension=10, cut_ratio=1e-09, trunc_tracking_mode='C', svd_ctrl='A', ini_bond_dimension=1)[source]

Convergence parameter class, inhereting from the more general Tensor Network type. Here the convergence parameters are only the bond dimension and the cut ratio.

Parameters

max_bond_dimensionint, optional

Maximum bond dimension of the problem. Default to 10.

cut_ratiofloat, optional

Cut ratio for singular values. If \(\lambda_n/\lambda_1 <\) cut_ratio then \(\lambda_n\) is neglected. Default to 1e-9.

trunc_tracking_modestr, optional

Modus for storing truncation, ‘M’ for maximum, ‘C’ for cumulated (default).

svd_ctrlcharacter, optional

Control for the SVD algorithm. Available: - “A” : automatic. Some heuristic is run to choose the best mode for the algorithm. The heuristic can be seen in qtealeaves/tensors/tensors.py in the function _process_svd_ctrl. - “V” : gesvd. Safe but slow method. - “D” : gesdd. Fast iterative method. It might fail. Resort to gesvd if it fails - “E” : eigenvalue decomposition method. Faster on GPU. Available only when contracting the singular value to left or right - “X” : sparse eigenvalue decomposition method. Used when you reach the maximum bond dimension. - “R” : random svd method. Used when you reach the maximum bond dimension. Default to ‘A’.

ini_bond_dimension: int, optional

Initial bond dimension of the simulation. It is used if the initial state is random. Default to 1.

classmethod from_json(path)[source]

Initialize the class from a json file

pretty_print()[source]

Print the convergence parameters. (Implemented to avoid too few public methods)

to_dict()[source]

Return the ordered dictionary of the properties of the class

Returns

dictionary: OrderedDict

Ordered dictionary of the class properties

to_json(path)[source]

Write the class as a json on file

class qmatchatea.utils.utils.QCIO(inPATH='data/in/', outPATH='data/out/', initial_state='Vacuum')[source]

Class to handle Input/Output parameters

Parameters

inPATH: str, optional

PATH to the directory containing the input files. Default to ‘data/in/’

outPATH: str, optional

PATH to the directory containing the output files. Default to ‘data/out/’

initial_state: str or MPS, optional

If an MPS, then the list of tensors is used as initial state for a starting point of the simulation. If ‘Vacuum’ start from |000…0>. Default to ‘Vacuum’. If a PATH it is a PATH to a saved MPS.

classmethod from_json(path)[source]

Initialize the class from a json file

property inPATH

Input PATH property

property initial_state

Initial state property

property outPATH

Output PATH property

set_initial_state(initial_state)[source]

Modify the initial state property

setup()[source]

Setup the io files

to_dict()[source]

Return the ordered dictionary of the properties of the class.

Returns

dictionary: OrderedDict

Ordered dictionary of the class properties

to_json(path)[source]

Write the class as a json on file

class qmatchatea.utils.utils.SimpleHamiltonian[source]

Simple class for an Hamiltonian that extends a normal dictionary. The keys are the pauli strings, the values the coefficients. It is used for simplicity, since it has a to_pauli_dict method equivalent to qiskit and other methods to ease the construction.

add_term(hterms, qubits, coeff)[source]

Add a term to the Hamiltonian acting on the qubits qubits. You do not need to specify the identities

Parameters

htermsstr or array-like

Pauli matrices to apply

qubitsint or array-like

Qubits where the terms acts

coeffcomplex

Coefficient of the term

Returns

None

set_num_qubits(num_qubits)[source]

Set the number of qubits the Hamiltonian is describing

Parameters

num_qubitsint

Number of qubits

to_pauli_dict()[source]

Get the qiskit pauli dict representation, that can be later used in the observable class

Returns

dict

dictionary with qiskit pauli_dict old format

qmatchatea.utils.utils.fidelity(psi, phi)[source]

Returns the fidelity bewteen two quantum states psi, phi defined as \(|\langle\psi|phi\rangle|^2\)

Parameters

psi: complex np.array or quimb.core.qarray

Quantum state

phi: complex np.array or quimb.core.qarray

Quantum state

Returns

Fidelity: double real

Fidelity of the two quantum states

qmatchatea.utils.utils.print_state(dense_state)[source]

Prints a dense_state with kets. Compatible with quimb states.

Parameters

dense_state: array_like

Dense representation of a quantum state

Returns

None: None